package com.randis.dailyplanner;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;

import com.randis.dailyplanner.dao.ActivitiesDao;
import com.randis.dailyplanner.dao.UserDao;
import com.randis.dailyplanner.managers.ActivitiesManager;
import com.randis.dailyplanner.managers.EmailManager;
import com.randis.dailyplanner.managers.UserManager;

/**
 * 
 * @author alpe
 */
public class ServiceLocator {

	private static ServiceLocator instance = new ServiceLocator();
	
	private PersistenceManagerFactory pmfInstance = JDOHelper.getPersistenceManagerFactory("transactions-optional");
	
	private ActivitiesDao 		activitiesDao;
	
	private UserDao 			userDao;

	private ActivitiesManager 	activitiesManager;

	private UserManager 		userManager;

	private EmailManager 		emailManager;
	
	public static ServiceLocator getInstance() {
		return instance;
	}
	
	public ActivitiesDao getActivitiesDao() {
		if (activitiesDao == null)
			activitiesDao = new ActivitiesDao();
		
		return activitiesDao;
	}

	public ActivitiesManager getActivitiesManager() {
		if (activitiesManager == null)
			activitiesManager = new ActivitiesManager();
		
		return activitiesManager;
	}

	public UserDao getUserDao() {
		if (userDao == null)
			userDao = new UserDao();
		
		return userDao;
	}

	public UserManager getUserManager() {
		if (userManager == null)
			userManager = new UserManager();
		
		return userManager;
	}

	public PersistenceManagerFactory getPMFInstance() {
		return pmfInstance;
	}

	public EmailManager getEmailManager() {
		if (emailManager == null)
			emailManager = new EmailManager();
		
		return emailManager;
	}
}
